<?php

namespace app\process;

use app\service\mqtt\MqttClient;
use support\Log;
use Workerman\Worker;

class Mqtt
{
    protected MqttClient $mqttClient;

    public function __construct()
    {
        $this->mqttClient = new MqttClient();
    }

    public function onWorkerStart(Worker $worker): void
    {
        Log::info("MQTT进程启动 [ID: {$worker->id}]");
        $this->mqttClient->connect();
    }

    public function onWorkerStop(Worker $worker): void
    {
        Log::info("MQTT进程停止 [ID: {$worker->id}]");
        $this->mqttClient->close();
    }

    /**
     * 获取MQTT客户端实例
     */
    public function getClient(): MqttClient
    {
        return $this->mqttClient;
    }
}